{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "from static_var import total_csv, llm_cls_prompt_pkl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append('..')\n",
    "\n",
    "from settings import prompt_cls, industry_info_template\n",
    "from utils import load_obj, save_obj"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "raw_df = pd.read_csv(total_csv)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def trans_data(row):\n",
    "    business = row.get(\"经营范围\")\n",
    "    name = row.get(\"企业名称\")\n",
    "    large = row.get(\"大类名称\")\n",
    "    mid = row.get(\"中类名称\")\n",
    "    small = row.get(\"小类名称\")\n",
    "    if (\n",
    "        not pd.isnull(name)\n",
    "        and isinstance(name, str)\n",
    "        and name.strip() != \"\"\n",
    "    ):\n",
    "        # return f\"{name}:\\n经营范围:{business};\\n大类名称:{large};\\n中类名称:{mid};\\n小类名称:{small};\"\n",
    "        return industry_info_template.format(name=name, business=business, large=large, mid=mid, small=small)\n",
    "    return \"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{name}:\\n经营范围:{business};\\n大类名称:{large};\\n中类名称:{mid};\\n小类名称:{small};'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "industry_info_template"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "raw_data = []\n",
    "for _, row in raw_df.iterrows():\n",
    "    industry_info = trans_data(row)\n",
    "    if industry_info:\n",
    "        raw_data.append(\n",
    "            # prompt1.format(industry_info=industry.industry_info)\n",
    "            # prompt_cls.format(industry_info = industry_info)\n",
    "            prompt_cls.replace(\"industry_info\", industry_info)\n",
    "        )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"\\n你是一位企业分类的专家。请仔细阅读企业信息：武汉兴祥农业科技发展有限公司:\\n经营范围:从事种养殖业及林果花卉;农业高科技的研究;开发;\\n大类名称: 农、林、牧、渔业;\\n中类名称: 农业;\\n小类名称:谷物种植;  \\n接下来，请从下述类别列表中选出最符合该企业信息的单一类别，并返回该类别名作为列表。  \\n若企业信息不属于下述任何类别，请返回['其他']。  \\n类别列表: ['光纤光缆、光器件/光模块、光系统设备等光通信', '芯片、半导体、存储器等集成电路', '显示器、液晶面板、触摸屏、虚拟现实、VR等显示', '手机、平板电脑、智能家居等智能终端', '5G网络', '互联网、云计算、大数据、物联网等', '传统汽车整车制造', '传统汽车关键核心零部件', '新能源整车制造', '新能源汽车关键核心零部件', '智能网联汽车配套产业', '汽车后市场服务', '医药流通', '生物制药、服务、制造等生物医药', '医疗器械', '生物农业', '健康服务', '3D打印与激光加工装备', '机器人', '高档数控机床', '绿色智能船舶、高技术船舶与海洋工程装备', '轨道交通装备', '工程机械装备', '高端能源装备', '金属新材料（含钢铁）', '石化化工新材料（含石化）', '无机非金属材料', '高性能纤维及制品和复合材料', '未来、前沿新材料', '电力、交通、建筑工程设计', '智能建造', '新零售、电子商务', '快递服务', '航空物流', '临港物流', '保税物流', '冷链物流', '货币金融服务', '证券服务', '投资服务', '保险业', '商务服务', '先进环保', '高效节能', '资源综合利用', '新型储能', '安全应急', '绿色消费品（含食品、纺织）', '滨江滨湖旅游', '夜色精品旅游', '生态休闲旅游', '红色文化旅游', '旅游演艺', '网络安全硬件', '网络安全软件（含元宇宙、区块链）', '网络安全服务', '航空维修及改装', '通航运营服务', '运载火箭及发射服务', '卫星制造及应用', '北斗基础构件', '北斗平台终端', '北斗应用服务', '人工智能芯片', '计算机视觉、自然语言处理、机器学习等AI技术', '无人机', '智能可穿戴设备', '智能机器人', '通用人工智能', '动漫设计', '游戏设计', '电竞直播', '设计服务', '数字传媒', '会议会展', '制氢、储氢及加氢等氢能设备', '电磁装备制造', '高速轨道交通', '量子通信', '量子计算', '量子测量', '超级计算', '类脑计算', '脑疾病诊疗', '脑机接口', '深地探测', '深海探测', '深空观测']  \\n返回格式：['类别名']  \\n\""
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "raw_data[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "save_obj(raw_data, llm_cls_prompt_pkl)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "llm",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
